package branch;

import gitobject.GitObject;
import repository.Repository;

import java.io.File;
import java.io.IOException;
import java.util.Date;

public class Branch {

    protected static String branchName;
    protected static String commitId;
    protected static String updateInfo;
    protected static String logsPath = Repository.getGitDir() + File.separator + "logs";
    protected static String refsPath = Repository.getGitDir() + File.separator + "refs" ;
    protected static  String Head = Repository.getGitDir() + File.separator + "logs" + File.separator + "Head";

    public Branch() {
    }

    public Branch(String commitId,String branchName) {
        this.commitId = commitId;
        this.branchName = branchName;
        this.updateInfo = commitId + " " + commitId + " " + System.getProperty("user.name") + " " + "<664941471@qq.com>" +" " + String.valueOf(new Date().getTime() ) ;
    }

    public Branch(String branchName) throws IOException {
        String path = Repository.getGitDir() + File.separator + "refs" + File.separator + "heads";
        this.branchName = branchName;
        File currBranchFile = new File(path + File.separator + branchName);
        commitId = GitObject.getValue(currBranchFile);
    }

    public String getUpdateInfo() {
        return updateInfo;
    }
//
//    public String getCommitId() {
//        return commitId;
//    }

    public static String getLogsPath() {
        return logsPath;
    }

    public static String getRefsPath() {
        return refsPath;
    }

//    public static String getHead() {
//        return Head;
//    }

}
